<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/common/taglibs.jsp" %>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">

    <title> - 登录</title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <link href="${ctx}/static/back/css/bootstrap.min.css" rel="stylesheet">
    <link href="${ctx}/static/back/css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="${ctx}/static/back/css/animate.css" rel="stylesheet">
    <link href="${ctx}/static/back/css/style.css" rel="stylesheet">
    <link href="${ctx}/static/back/css/login.css" rel="stylesheet">
    
     <link rel="stylesheet" href="${ctx}/static/lib/layui/css/layui.css">
    <!--[if lt IE 9]>
    <meta http-equiv="refresh" content="0;ie.html" />
    <![endif]-->
    <script>
        if (window.top !== window.self) {
            window.top.location = window.location;
        }
    </script>

</head>

<body class="signin">
    <div class="signinpanel">
        <div class="row">
            <div class="col-sm-12">
                <form id="login_form" method="post">
                    <h4 class="no-margins">登录：</h4>
                    <p class="m-t-md">登录到H+后台主题UI框架</p>
                    <input type="text" id="username" name="username" class="form-control uname" placeholder="用户名" />
                    <input type="password" id="password" name="password" class="form-control pword m-b" placeholder="密码" />
                    <a href="">忘记密码了？</a>
                </form>
                <button class="btn btn-success btn-block" onclick="submitForm()">登录</button>
            </div>
        </div>
        <div class="signup-footer">
            <div class="pull-left">
                &copy; hAdmin
            </div>
        </div>
        <script src="${ctx}/static/back/js/jquery.min.js?v=2.1.4"></script>
        <script src="${ctx}/static/common/mylayer.js"></script>
        <script src="${ctx}/static/common/util.js"></script>
        <script src="${ctx}/static/lib/layui/layui.js"></script>
 		<script>
			//一般直接写在一个js文件中
			layui.use(['layer'], function(){
			  var layer = layui.layer;
			  //layer.msg('Hello World');
			});
		</script> 
        <script type="text/javascript">
        	function submitForm() {
        		/* 1、验证用户名
        		1.1、用户名不能为空
        		1.2、是否合法：4-8位数字或字母
        		2、密码不能为空
        		3、ajax提交用户名和密码，根据后台返回的ServerResponse决定进行什么操作 */
        		var username = $("#username").val();
        		var password = $("#password").val();
        		// 1.1、用户名不能为空
        		if(util.isNull(username)) {
        			mylayer.errorMsg("用户名不能为空");
        			return;
        		}
        		// 1.2、是否合法：4-8位数字或字母
        		var pattern = /^[0-9a-zA-Z]{4,8}$/;
        		if(!pattern.test(username)) {
        			mylayer.errorMsg("格式非法，请输入4-8位数字或字母");
        			return;
        		}
        		//2、密码不能为空
        		if(util.isNull(password)) {
        			mylayer.errorMsg("密码不能为空");
        			return;
        		}
        		
        		//3、ajax提交用户名和密码，根据后台返回的ServerResponse决定进行什么操作
        		$.ajax({
        			url:"${ctx}/user/login.action",
        			type:"post",
        			dataType:"json",
        			data:$("#login_form").serialize(),
        			success:function(resp) {
        				console.log(resp);
        				if(resp.code == util.SUCCESS){
        					mylayer.successUrl(resp.msg, "${ctx}/index.action");
        				} else {
        					mylayer.errorMsg(resp.msg);
        				}
        			}
        		});
        		
        	}
        </script>
    </div>
</body>

</html>
